package com.simonall.utils;

import com.simonall.enums.ResponseCodeEnum;

import lombok.Data;
import lombok.EqualsAndHashCode;
import lombok.NoArgsConstructor;
import lombok.experimental.FieldNameConstants;

/**
 * Business Exception
 * 
 * @author simonall
 */
@Data
@NoArgsConstructor
@FieldNameConstants
@EqualsAndHashCode(callSuper = true)
public class BusinessException extends RuntimeException {

	private static final long serialVersionUID = -7788139025302596985L;

	// 代码
	private String code;

	// 描述
	private String desc;

	/**
	 * 单描述构造器
	 * 
	 * @param desc
	 */
	public BusinessException(String desc) {
		super(desc);
		this.code = "FAIL";
		this.desc = desc;
	}

	/**
	 * 完全参数构造器
	 * 
	 * @param code
	 * @param desc
	 */
	public BusinessException(String code, String desc) {
		super(desc);
		this.code = code;
		this.desc = desc;
	}

	/**
	 * 单描述构造器
	 * 
	 * @param desc
	 */
	public BusinessException(ResponseCodeEnum response) {
		super(response.getDesc());
		this.code = response.getCode();
		this.desc = response.getDesc();
	}

	public BusinessException setCode(String code) {
		this.code = code;
		return this;
	}

	public BusinessException setMessage(String desc) {
		this.desc = desc;
		return this;
	}
}
